<template>
  <div class="app-container">
    <!--  -->
    <!-- 统计卡片 -->
    <div class="stats-container">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-card class="stat-card total-card" shadow="hover">
            <div class="stat-content">
              <div class="stat-icon">
                <i class="el-icon-user"></i>
              </div>
              <div class="stat-info">
                <div class="stat-number">{{ total }}</div>
                <div class="stat-label">总认领记录</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="stat-card urgency-card" shadow="hover">
            <div class="stat-content">
              <div class="stat-icon">
                <i class="el-icon-warning"></i>
              </div>
              <div class="stat-info">
                <div class="stat-number">紧急: {{ urgencyStats.紧急 }} / 一般: {{ urgencyStats.一般 }} / 不紧急: {{ urgencyStats.不紧急 }}</div>
                <div class="stat-label">项目紧急程度</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="stat-card followup-card" shadow="hover">
            <div class="stat-content">
              <div class="stat-icon">
                <i class="el-icon-s-flag"></i>
              </div>
              <div class="stat-info">
                <div class="stat-number">未跟进: {{ followUpStats['未跟进'] }} / 跟进中: {{ followUpStats['跟进中'] }} / 已跟进: {{ followUpStats['已跟进'] }}</div>
                <div class="stat-label">跟进状态</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="stat-card days-card" shadow="hover">
            <div class="stat-content">
              <div class="stat-icon">
                <i class="el-icon-time"></i>
              </div>
              <div class="stat-info">
                <div class="stat-number">平均: {{ followUpDaysStats.average }}天 / 最长: {{ followUpDaysStats.max }}天 / 最短: {{ followUpDaysStats.min }}天</div>
                <div class="stat-label">跟进天数统计</div>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 搜索卡片 -->
    <el-card class="search-card" shadow="hover">
      <div slot="header" class="card-header">
        <span class="card-title">
          <i class="el-icon-search"></i>
          搜索条件
        </span>
        <div class="header-actions">
          <el-button type="text" @click="toggleSearch">
            {{ showSearch ? '收起' : '展开' }}
            <i :class="showSearch ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"></i>
          </el-button>
          <el-button type="text" @click="resetQuery" icon="el-icon-refresh">重置</el-button>
        </div>
      </div>

      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item label="客户名称" prop="customerName">
              <el-input
                v-model="queryParams.customerName"
                placeholder="请输入客户名称"
                clearable
                @keyup.enter.native="handleQuery"
                prefix-icon="el-icon-office-building"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="跟进状态" prop="followUpStatus">
              <el-select v-model="queryParams.followUpStatus" placeholder="请选择跟进状态" clearable style="width: 100%">
                <el-option label="未跟进" value="未跟进"></el-option>
                <el-option label="跟进中" value="跟进中"></el-option>
                <el-option label="已跟进" value="已跟进"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="客户来源" prop="source">
              <el-select
                v-model="queryParams.source"
                placeholder="请选择来源"
                clearable
                style="width: 100%"
              >
                <el-option label="拓客来源" value="0"></el-option>
                <el-option label="个人来源" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-form-item label="项目紧急程度" prop="urgencyLevel">
              <el-select
                v-model="queryParams.urgencyLevel"
                placeholder="请选择项目紧急程度"
                clearable
                style="width: 100%"
              >
              <el-option label="紧急" value="紧急"></el-option>
                    <el-option label="一般" value="一般"></el-option>
                    <el-option label="不紧急" value="不紧急"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6" style="display: flex; justify-content: flex-end; padding-right: 360px;">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>

    <!-- 操作按钮卡片 -->
    <el-card class="action-card" shadow="hover">
      <div class="action-buttons">
        <div class="left-buttons">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['customer:customer_claim:add']"
          >新增认领</el-button>
          <el-button
            type="success"
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['customer:customer_claim:edit']"
          >修改</el-button>
          <el-button
            type="danger"
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['customer:customer_claim:remove']"
          >删除</el-button>
          <el-button
            type="warning"
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['customer:customer_claim:export']"
          >导出</el-button>
        </div>
        <div class="right-buttons">
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </div>
      </div>
    </el-card>

    <!-- 数据展示卡片 -->
    <el-card class="data-card" shadow="hover">
      <div slot="header" class="card-header">
        <span class="card-title">
          <i class="el-icon-user"></i>
          拓客认领记录列表
        </span>
        <span class="card-subtitle">共 {{ total }} 条记录</span>
      </div>

      <el-table v-loading="loading" :data="customer_claimList" @selection-change="handleSelectionChange" stripe border class="custom-table">
        <el-table-column type="selection" width="55" align="center" />  
        <el-table-column label="来源" align="center" prop="source" min-width="100">
          <template slot-scope="scope">
            <el-tag type="info" size="mini" effect="plain">
              <i class="el-icon-connection"></i>
              {{ scope.row.source === 0 ? '拓客来源' : scope.row.source === 1 ? '个人来源' : scope.row.source }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="客户分类" align="center" prop="customerClass" min-width="100" />
        <el-table-column label="项目紧急程度" align="center" prop="urgencyLevel" min-width="120">
          <template slot-scope="scope">
            <el-tag
              :type="getUrgencyLevelType(scope.row.urgencyLevel)"
              :color="getUrgencyLevelColor(scope.row.urgencyLevel)"
              effect="dark"
              size="mini"
            >
              <i :class="getUrgencyLevelIcon(scope.row.urgencyLevel)"></i>
              {{ scope.row.urgencyLevel }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="拓客创建人" align="center" prop="prospectCreator" min-width="120">
          <template slot-scope="scope">
            <div class="creator-info">
              <i class="el-icon-user"></i>
              <span>{{ scope.row.prospectCreator }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="认领日期" align="center" prop="claimDate" width="120">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.claimDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户名称" align="center" prop="customerName" min-width="150" show-overflow-tooltip>
          <template slot-scope="scope">
            <div class="customer-name">
              <i class="el-icon-office-building"></i>
              <span>{{ scope.row.customerName }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="联络人" align="center" prop="contactPerson" min-width="100">
          <template slot-scope="scope">
            <div class="contact-person">
              <i class="el-icon-user"></i>
              <span>{{ scope.row.contactPerson }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="联络电话" align="center" prop="contactPhone" min-width="130">
          <template slot-scope="scope">
            <div class="contact-phone">
              <i class="el-icon-phone"></i>
              <span>{{ scope.row.contactPhone }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="其他联络方式" align="center" prop="otherContactMethods" min-width="130" show-overflow-tooltip />
        <el-table-column label="客户来源" align="center" prop="customerSource" min-width="120">
          <template slot-scope="scope">
            <el-tag type="info" size="mini" effect="plain">
              <i class="el-icon-connection"></i>
              {{ scope.row.customerSource }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="跟进状态" align="center" prop="followUpStatus" min-width="120">
          <template slot-scope="scope">
            <el-tag
              :type="getFollowUpStatusType(scope.row.followUpStatus)"
              :color="getFollowUpStatusColor(scope.row.followUpStatus)"
              effect="dark"
              size="mini"
            >
              <i :class="getFollowUpStatusIcon(scope.row.followUpStatus)"></i>
              {{ scope.row.followUpStatus }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="跟进天数" align="center" prop="followUpDays" min-width="100" />
        <el-table-column label="操作日期" align="center" prop="operationDate" width="120">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.operationDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="认领人" align="center" prop="claimer" min-width="100">
          <template slot-scope="scope">
            <div class="claimer-info">
              <i class="el-icon-user"></i>
              <span>{{ scope.row.claimer }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center" prop="remarks" min-width="150" show-overflow-tooltip />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleView(scope.row)"
            >查看</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['customer:customer_claim:edit']"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['customer:customer_claim:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>

    <!-- 添加或修改拓客认领记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-tabs v-model="activeTab" type="border-card">
          <el-tab-pane label="基本信息" name="basic">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="来源" prop="source">
                  <el-select v-model="form.source" placeholder="请选择来源" clearable style="width: 100%">
                    <el-option label="拓客来源" :value="0"></el-option>
                    <el-option label="个人来源" :value="1"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="客户分类" prop="customerClass">
                  <el-input v-model="form.customerClass" placeholder="请输入客户分类" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="项目紧急程度" prop="urgencyLevel">
                  <el-select v-model="form.urgencyLevel" placeholder="请选择项目紧急程度" clearable style="width: 100%">
                    <el-option label="紧急" value="紧急"></el-option>
                    <el-option label="一般" value="一般"></el-option>
                    <el-option label="不紧急" value="不紧急"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="拓客创建人" prop="prospectCreator">
                  <el-input v-model="form.prospectCreator" placeholder="请输入拓客创建人" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="认领日期" prop="claimDate">
                  <el-date-picker clearable
                    v-model="form.claimDate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择认领日期"
                    style="width: 100%">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="客户名称" prop="customerName">
                  <el-input v-model="form.customerName" placeholder="请输入客户名称" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>

          <el-tab-pane label="联系信息" name="contact">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="联络人" prop="contactPerson">
                  <el-input v-model="form.contactPerson" placeholder="请输入联络人" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="联络电话" prop="contactPhone">
                  <el-input v-model="form.contactPhone" placeholder="请输入联络电话" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="其他联络方式" prop="otherContactMethods">
                  <el-input v-model="form.otherContactMethods" placeholder="请输入其他联络方式" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="客户来源" prop="customerSource">
                  <el-select v-model="form.customerSource" placeholder="请选择客户来源" clearable style="width: 100%">
                    <el-option label="线上咨询" value="线上咨询"></el-option>
                    <el-option label="展会" value="展会"></el-option>
                    <el-option label="客户介绍" value="客户介绍"></el-option>
                    <el-option label="朋友介绍" value="朋友介绍"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>

          <el-tab-pane label="跟进信息" name="followup">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="跟进状态" prop="followUpStatus">
                  <el-select v-model="form.followUpStatus" placeholder="请选择跟进状态" clearable style="width: 100%">
                    <el-option label="未跟进" value="未跟进"></el-option>
                    <el-option label="跟进中" value="跟进中"></el-option>
                    <el-option label="已跟进" value="已跟进"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="跟进天数" prop="followUpDays">
                  <el-input v-model="form.followUpDays" placeholder="请输入跟进天数" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="操作日期" prop="operationDate">
                  <el-date-picker clearable
                    v-model="form.operationDate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择操作日期"
                    style="width: 100%">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="认领人" prop="claimer">
                  <el-input v-model="form.claimer" placeholder="请输入认领人" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="24">
                <el-form-item label="备注" prop="remarks">
                  <el-input v-model="form.remarks" type="textarea" :rows="4" placeholder="请输入备注" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  <!-- 详情弹窗 -->
  <el-dialog title="认领详情" :visible.sync="viewOpen" width="800px" append-to-body>
    <div class="customer-detail">
      <el-descriptions :column="2" border>
        <el-descriptions-item label="来源">
          <el-tag type="info" size="mini">
            {{ viewForm.source === 0 ? '拓客来源' : viewForm.source === 1 ? '个人来源' : viewForm.source }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="客户分类">{{ viewForm.customerClass }}</el-descriptions-item>
        <el-descriptions-item label="项目紧急程度">
          <el-tag :type="getUrgencyLevelType(viewForm.urgencyLevel)" size="mini">
            {{ viewForm.urgencyLevel }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="拓客创建人">{{ viewForm.prospectCreator }}</el-descriptions-item>
        <el-descriptions-item label="认领日期">{{ parseTime(viewForm.claimDate, '{y}-{m}-{d}') }}</el-descriptions-item>
        <el-descriptions-item label="客户名称">{{ viewForm.customerName }}</el-descriptions-item>
        <el-descriptions-item label="联络人">{{ viewForm.contactPerson }}</el-descriptions-item>
        <el-descriptions-item label="联络电话">{{ viewForm.contactPhone }}</el-descriptions-item>
        <el-descriptions-item label="其他联络方式">{{ viewForm.otherContactMethods }}</el-descriptions-item>
        <el-descriptions-item label="客户来源">{{ viewForm.customerSource }}</el-descriptions-item>
        <el-descriptions-item label="跟进状态">
          <el-tag :type="getFollowUpStatusType(viewForm.followUpStatus)" size="mini">
            {{ viewForm.followUpStatus }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="跟进天数">{{ viewForm.followUpDays }}</el-descriptions-item>
        <el-descriptions-item label="操作日期">{{ parseTime(viewForm.operationDate, '{y}-{m}-{d}') }}</el-descriptions-item>
        <el-descriptions-item label="认领人">{{ viewForm.claimer }}</el-descriptions-item>
        <el-descriptions-item label="备注" :span="2">{{ viewForm.remarks }}</el-descriptions-item>
      </el-descriptions>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="viewOpen = false">关 闭</el-button>
    </div>
  </el-dialog>
</div>
</template>

<script>
import { listCustomer_claim, getCustomer_claim, delCustomer_claim, addCustomer_claim, updateCustomer_claim } from "@/api/customer/customer_claim"

export default {
  name: "Customer_claim",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 拓客认领记录表格数据
      customer_claimList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 当前激活的标签页
      activeTab: 'basic',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerName: null,
        source:null,
        followUpStatus: null,
      },
      // 统计数据
      followUpStats: { '未跟进': 0, '跟进中': 0, '已跟进': 0 }, // 合并跟进状态统计
      urgencyStats: { 紧急: 0, 一般: 0, 不紧急: 0 },
      followUpDaysStats: { average: 0, max: 0, min: 0 }, // 跟进天数统计
      // 表单参数
      form: {},
      // 详情弹窗参数
      viewOpen: false,
      viewForm: {},
      // 表单校验
      rules: {
        source:[
          { required: true, message: "来源不能为空", trigger: "blur" }
        ],
        customerClass:[
          { required: true, message: "客户分类不能为空", trigger: "blur" }
        ],
        urgencyLevel:[
          { required: true, message: "项目紧急程度不能为空", trigger: "blur" }
        ],
        customerName:[
          { required: true, message: "客户名称不能为空", trigger: "blur" }
        ],
        customerSource:[
          { required: true, message: "客户来源不能为空", trigger: "blur" }
        ],
        followUpStatus:[
          { required: true, message: "跟进状态不能为空", trigger: "blur" }
        ],
        followUpDays:[
          { required: true, message: "跟进天数不能为空", trigger: "blur" }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询拓客认领记录列表 */
    getList() {
      this.loading = true
      listCustomer_claim(this.queryParams).then(response => {
        this.customer_claimList = response.rows
        this.total = response.total
        this.calculateStats()
        this.loading = false
      })
    },
    /** 计算统计数据 */
    calculateStats() {
      // 统计跟进状态和项目紧急程度
      this.followUpStats = { '未跟进': 0, '跟进中': 0, '已跟进': 0 };
      this.urgencyStats = { 紧急: 0, 一般: 0, 不紧急: 0 };
      
      // 跟进天数统计
      const followUpDaysList = [];
      
      this.customer_claimList.forEach(item => {
        // 统计跟进状态
        if (item.followUpStatus === '未跟进') this.followUpStats['未跟进']++;
        else if (item.followUpStatus === '跟进中') this.followUpStats['跟进中']++;
        else if (item.followUpStatus === '已跟进') this.followUpStats['已跟进']++;
        
        // 统计项目紧急程度
        if (item.urgencyLevel === '紧急') this.urgencyStats.紧急++;
        else if (item.urgencyLevel === '一般') this.urgencyStats.一般++;
        else if (item.urgencyLevel === '不紧急') this.urgencyStats.不紧急++;
        
        // 收集跟进天数数据
        if (item.followUpDays && !isNaN(parseInt(item.followUpDays))) {
          followUpDaysList.push(parseInt(item.followUpDays));
        }
      });
      
      // 计算跟进天数统计
      if (followUpDaysList.length > 0) {
        const sum = followUpDaysList.reduce((acc, curr) => acc + curr, 0);
        this.followUpDaysStats.average = Math.round(sum / followUpDaysList.length);
        this.followUpDaysStats.max = Math.max(...followUpDaysList);
        this.followUpDaysStats.min = Math.min(...followUpDaysList);
      } else {
        this.followUpDaysStats = { average: 0, max: 0, min: 0 };
      }
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        source: null,
        customerClass: null,
        urgencyLevel: null,
        prospectCreator: null,
        claimDate: null,
        customerName: null,
        contactPerson: null,
        contactPhone: null,
        otherContactMethods: null,
        customerSource: null,
        followUpStatus: null,
        followUpDays: null,
        operationDate: null,
        claimer: null,
        remarks: null
      }
      this.resetForm("form")
      this.activeTab = 'basic'
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加拓客认领记录"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getCustomer_claim(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改拓客认领记录"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCustomer_claim(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addCustomer_claim(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除拓客认领记录编号为"' + ids + '"的数据项？').then(function() {
        return delCustomer_claim(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('customer/customer_claim/export', {
        ...this.queryParams
      }, `customer_claim_${new Date().getTime()}.xlsx`)
    },
    /** 查看详情按钮操作 */
    handleView(row) {
      const id = row.id || this.ids
      getCustomer_claim(id).then(response => {
        this.viewForm = response.data
        this.viewOpen = true
      })
    },
    /** 切换搜索显示 */
    toggleSearch() {
      this.showSearch = !this.showSearch
    },
    /** 获取跟进状态标签类型 */
    getFollowUpStatusType(status) {
      switch (status) {
        case '未跟进':
          return 'danger'
        case '跟进中':
          return 'warning'
        case '已跟进':
          return 'success'
        default:
          return 'info'
      }
    },
    /** 获取跟进状态颜色 */
    getFollowUpStatusColor(status) {
      switch (status) {
        case '未跟进':
          return '#F56C6C'
        case '跟进中':
          return '#E6A23C'
        case '已跟进':
          return '#67C23A'
        default:
          return '#909399'
      }
    },
    /** 获取跟进状态图标 */
    getFollowUpStatusIcon(status) {
      switch (status) {
        case '未跟进':
          return 'el-icon-close'
        case '跟进中':
          return 'el-icon-time'
        case '已跟进':
          return 'el-icon-check'
        default:
          return 'el-icon-info'
      }
    },
    /** 获取项目紧急程度标签类型 */
    getUrgencyLevelType(level) {
      switch (level) {
        case '紧急':
          return 'danger'
        case '一般':
          return 'warning'
        case '不紧急':
          return 'success'
        default:
          return 'info'
      }
    },
    /** 获取项目紧急程度颜色 */
    getUrgencyLevelColor(level) {
      switch (level) {
        case '紧急':
          return '#F56C6C'
        case '一般':
          return '#E6A23C'
        case '不紧急':
          return '#67C23A'
        default:
          return '#909399'
      }
    },
    /** 获取项目紧急程度图标 */
    getUrgencyLevelIcon(level) {
      switch (level) {
        case '紧急':
          return 'el-icon-warning'
        case '一般':
          return 'el-icon-time'
        case '不紧急':
          return 'el-icon-check'
        default:
          return 'el-icon-info'
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: calc(100vh - 84px);
}

.stats-container {
  margin-bottom: 20px;

  .stat-card {
    border-radius: 12px;
    border: none;
    transition: all 0.3s ease;

    &:hover {
      transform: translateY(-5px);
      box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    }

    .stat-content {
      display: flex;
      align-items: center;
      padding: 10px;

      .stat-icon {
        width: 60px;
        height: 60px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 15px;

        i {
          font-size: 24px;
          color: white;
        }
      }

      .stat-info {
        flex: 1;

        .stat-number {
          font-size: 28px;
          font-weight: bold;
          color: #303133;
          line-height: 1;
          margin-bottom: 5px;
        }

        .stat-label {
          font-size: 14px;
          color: #909399;
        }
      }
    }

    &.total-card .stat-icon {
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    }

    &.urgency-card .stat-icon {
      background: linear-gradient(135deg, #ffb347 0%, #ffcc33 100%);
    }

    &.followup-card .stat-icon {
      background: linear-gradient(135deg, #409eff 0%, #50e3c2 100%);
    }

    &.days-card .stat-icon {
      background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
    }
  }
}

.search-card {
  margin-bottom: 20px;
  border-radius: 12px;

  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0;

    .card-title {
      font-size: 16px;
      font-weight: 600;
      color: #303133;

      i {
        margin-right: 8px;
        color: #409eff;
      }
    }

    .header-actions {
      display: flex;
      gap: 10px;
    }
  }
}

.action-card {
  margin-bottom: 20px;
  border-radius: 12px;

  .action-buttons {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;

    .left-buttons,
    .right-buttons {
      display: flex;
      gap: 10px;
      flex-wrap: wrap;
    }
  }
}

.data-card {
  border-radius: 12px;

  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0;

    .card-title {
      font-size: 16px;
      font-weight: 600;
      color: #303133;

      i {
        margin-right: 8px;
        color: #409eff;
      }
    }

    .card-subtitle {
      font-size: 14px;
      color: #909399;
    }
  }
}

.custom-table {
  border-radius: 8px;
  overflow: hidden;

  ::v-deep .el-table__header-wrapper {
    background-color: #fafafa;
  }

  ::v-deep .el-table__row {
    transition: all 0.3s ease;
    cursor: pointer;

    &:hover {
      background-color: #f5f7fa !important;
    }
  }

  ::v-deep .el-table__cell {
    padding: 12px 0;
  }

  .customer-name,
  .contact-person,
  .contact-phone,
  .creator-info,
  .claimer-info {
    display: flex;
    align-items: center;
    justify-content: center;

    i {
      margin-right: 5px;
      color: #409eff;
    }
  }
}

::v-deep .el-card {
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  border: none;

  &:hover {
    box-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.15);
  }
}

::v-deep .el-button {
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.3s ease;

  &.el-button--primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;

    &:hover {
      background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
      transform: translateY(-2px);
    }
  }

  &.el-button--success {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    border: none;

    &:hover {
      background: linear-gradient(135deg, #0f8a7d 0%, #2dd66e 100%);
      transform: translateY(-2px);
    }
  }

  &.el-button--danger {
    background: linear-gradient(135deg, #ff416c 0%, #ff4b2b 100%);
    border: none;

    &:hover {
      background: linear-gradient(135deg, #e63a5f 0%, #e64426 100%);
      transform: translateY(-2px);
    }
  }

  &.el-button--warning {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border: none;

    &:hover {
      background: linear-gradient(135deg, #d884e2 0%, #d44e5f 100%);
      transform: translateY(-2px);
    }
  }

  &.el-button--info {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    border: none;

    &:hover {
      background: linear-gradient(135deg, #45a1f0 0%, #00e5f0 100%);
      transform: translateY(-2px);
    }
  }
}

::v-deep .el-tag {
  border-radius: 6px;
  font-weight: 500;

  &.el-tag--info {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
  }
}

::v-deep .el-pagination {
  margin-top: 20px;
  text-align: center;
}

::v-deep .el-dialog {
  border-radius: 12px;

  .el-dialog__header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px 12px 0 0;

    .el-dialog__title {
      color: white;
      font-weight: 600;
    }
  }
}

::v-deep .el-form-item__label {
  font-weight: 500;
  color: #606266;
}

::v-deep .el-input__inner {
  border-radius: 8px;
  border: 1px solid #dcdfe6;
  transition: all 0.3s ease;

  &:focus {
    border-color: #409eff;
    box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
  }
}

::v-deep .el-select .el-input__inner {
  border-radius: 8px;
}

::v-deep .el-textarea__inner {
  border-radius: 8px;
  border: 1px solid #dcdfe6;
  transition: all 0.3s ease;

  &:focus {
    border-color: #409eff;
    box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
  }
}

::v-deep .el-tabs--border-card {
  border-radius: 8px;
  box-shadow: none;
  border: 1px solid #dcdfe6;
}

::v-deep .el-tabs--border-card>.el-tabs__header {
  background-color: #f5f7fa;
  border-bottom: 1px solid #dcdfe6;
}

::v-deep .el-tabs--border-card>.el-tabs__header .el-tabs__item {
  border-radius: 6px 6px 0 0;
  margin-right: 5px;

  &.is-active {
    background-color: #409eff;
    color: white;
    border-color: #409eff;
  }
}
</style>
